<?php
use yii\helpers\Url;
use yii\web\View;
use app\assets\SolutionResourceAsset;
SolutionResourceAsset::register($this);
$this->title = $this->context->pageTitle.Yii::$app->params['titleSuffix'];
$this->params['breadcrumbs'] = [
  [
    'label' => \Yii::t('solution', 'Solution'),
    'url' => ['solution-list']
  ],
  \Yii::t('solution', 'New Solution')
];
$jsMsgs = $this->context->loadJsMsgs([
  'solution'
]);
$this->registerJs("VAM.setVar('LANGUAGE_JS', '".$jsMsgs."');", View::POS_HEAD);
?>
<div class="page-header">
  <h1>
    <?=\Yii::t('solution', 'Solution')?>
    <small><?=\Yii::t('solution', 'New Solution')?></small>
  </h1>
</div>
<div class="panel panel-default">
  <div class="panel-heading">
    <i class="fa fa-plus-circle"></i>
    <?=\Yii::t('solution', 'New Solution')?>
    <ul class="list-unstyled pull-right">
      <li>
        <a href="#">
          <i class="fa fa-chevron-up"></i>
        </a>
      </li>
    </ul>
  </div>
	<div class="panel-body">
    <div class="panel-heading">
      <h3 id="strategy_name"><?=$solution['name']?></h3>
    </div>
    <div class="step-container">
      <ul class="step-wrap">
        <li class="step-undone step-done">
          <a href="javascript:void(0);" title="<?=\Yii::t('common', 'Add Label')?>">
            <i class="fa fa-check"></i>
          </a>
          <p><?=\Yii::t('common', 'Add Label')?></p>
        </li>
        <li class="step-undone step-done">
          <a href="javascript:void(0);" title="<?=\Yii::t('common', 'Add Campaign')?>">
            <i class="fa fa-check"></i>
          </a>
          <p><?=\Yii::t('common', 'Add Campaign')?></p>
        </li>
         <li class="step-undone step-active">
          <a href="javascript:void(0);" title="<?=\Yii::t('common', 'Add Solution')?>">
            <i class="fa fa-chevron-right"></i>
          </a>
          <p><?=\Yii::t('common', 'Add Solution')?></p>
        </li>
         <li class="step-undone">
          <a href="javascript:void(0);" title="<?=\Yii::t('common', 'Add Creative')?>">
            <i class="fa fa-chevron-right"></i>
          </a>
          <p><?=\Yii::t('common', 'Add Creative')?></p>
        </li>
      </ul>
      <div class="step-progress-bar">
        <div class="step-progress" style="width: 66%;"></div>
      </div>
    </div>
    <div class="row">
      <div class="col-sm-12">
        <div class="section-step">
          <ol class="list-inline main-flow">
            <li class="first">
              <a href="<?= Url::to(['new-solution-basic']);?>?solution_id=<?=$solution['id'] ?>" class="cancleFocus">
                <b>①</b>
                <?=\Yii::t('solution', 'Basic')?>
                <span><i class="fa fa-arrow-right"></i></span>
              </a>
            </li>
            <li class="current">
              <a href="javascript:void(0);" class="cancleFocus">
                <b>②</b>
                <?=\Yii::t('solution', 'Resource')?>
                <span><i class="fa fa-arrow-right"></i></span>
              </a>
            </li>
            <li>
              <a href="javascript:void(0);" class="cancleFocus">
                <b>③</b>
                <?=\Yii::t('solution', 'Condition')?>
                <span><i class="fa fa-arrow-right"></i></span>
              </a>
            </li>
            <li>
              <a href="javascript:void(0);" class="cancleFocus">
                <b>④</b>
                <?=\Yii::t('solution', 'Bidding')?>
                <span><i class="fa fa-arrow-right"></i></span>
              </a>
            </li>
            <li class="last">
              <a href="javascript:void(0);" class="cancleFocus">
                <b>⑤</b>
                <?=\Yii::t('solution', 'Creative')?>
              </a>
            </li>
          </ol>
        </div>
      </div>
    </div>
		<div class="row">
			<div class="col-sm-8 col-sm-offset-2">
        <form class="form-horizontal" id="data-frm" method="POST" action="<?= Url::to(['new-solution-resource-handle']);?>" >
          <input class="hidden" type="text" name="solution_id" value="<?=$solution['id']?>">
          <fieldset>
            <legend><?=\Yii::t('solution', 'Resource')?></legend>
            <div class="form-group vam-hidden">
              <label class="control-label col-sm-2">
                <?=\Yii::t('solution', 'Resource Type')?>:
              </label>
              <div class="col-sm-10">
                 <label class="radio-inline col-sm-3">
                  <input id="resource_rtb_radio" type="radio" name="resource_type" value="0" 
				  <?php
						if ($solution['is_pmp'] == 0) {
							echo " checked ";
						}
				  ?> disabled>RTB
                </label>
                <label class="radio-inline col-sm-3">
                  <input id="resource_pmp_radio" type="radio" name="resource_type" value="1"
				  <?php
						if ($solution['is_pmp'] == 1) {
							echo " checked ";
						}
				  ?> disabled>PMP
                </label>
              </div>
            </div>
            <div class="form-group vam-hidden">
              <label class="control-label col-sm-2">
                <?=\Yii::t('solution', 'Pack Type')?>：
              </label>
              <div class="col-sm-10">
                  <label class="radio-inline">
                  <input class='pack-type' type="radio" name="pack_type_radio" value="1" checked >
                  <?=\Yii::t('solution', 'APP')?>
                </label>
                <label class="radio-inline">
                  <input class='pack-type' type="radio" name="pack_type_radio" value="2">
                  <?=\Yii::t('solution', 'WAP')?>
                </label>
              </div>
            </div>
            <div class="<?php if ($solution['is_pmp'] == 1) echo 'vam-hidden';?>" id="rtb_resource_type">
              <div class="form-group">
                <label class="control-label col-sm-2">
                  <?=\Yii::t('solution', 'Target type')?>：
                </label>
                <div class="col-sm-10">
                   <label class="radio-inline">
                    <input id="adspace_black_white_radio" type="radio" name="adspace.black_white_radio" value="no_limit" checked>
                    <?=\Yii::t('solution', 'no limit')?>
                  </label>
                  <label class="radio-inline">
                    <input id="adspace_black_white_radio" type="radio" name="adspace.black_white_radio" value="black">
                    <?=\Yii::t('solution', 'black')?>
                  </label>
                  <label class="radio-inline">
                    <input id="adspace_black_white_radio" type="radio" name="adspace.black_white_radio" value="white">
                    <?=\Yii::t('solution', 'white')?>
                  </label>
                </div>
              </div>
              <div class="form-group target-form hidden">
                <label for="rtb_network" class="col-sm-2 control-label">
                  <?=\Yii::t('solution', 'Market')?>：
                </label>
                <div class="col-sm-10">
<!--                   <label class="radio-inline">
					<input type="hidden" name="ad_network_id" value="1">
                    <input type="radio" name="ad_network[]" value="1" checked> <?=\Yii::t('solution', 'High Quality Resource')?>
                  </label> -->
                  <?php
                    $out = '';
                    foreach ($adnetworks as $adnetwork) {
                      $check = '';
                      $id = $adnetwork['id'];
                      $name = $adnetwork['channel'];
                      $id == 1 && $name = \Yii::t('solution', 'High Quality Resource');
                      $id == 1 && $check = "checked";
                      $out .= <<<FINE
                        <label class="radio-inline pl0">
                          <input type="checkbox" name="ad_network[]" value="$id" checked> $name
                        </label>
FINE;
                    }
                    echo $out;
                  ?>
                  <div class="help-block text-error" id="market_err"></div>
                </div>
              </div>
              <div class="form-group target-form vam-hidden">
                <label for="" class="col-sm-2 control-label">
                </label>
                <div class="col-sm-10">
                  <label class="radio-inline">
                    <input type="radio" name="adspace_check" value="all" checked><?=\Yii::t('solution', 'All')?>
                  </label>
                   <label class="radio-inline">
                    <input type="radio" name="adspace_check" value="part"><?=\Yii::t('solution', 'Part')?>
                  </label>
                </div>
              </div>
              <div class="form-group target-form vam-hidden" id="target_pack_form">
                <label for="" class="col-sm-2 control-label">
                  <?=\Yii::t('solution', 'Add Pack')?>：
                </label>
                <div class="col-sm-5">
                  <div id="app-pack-list-container" class='pack-list-container'>
                <?php
                    $packDiv = '<ul>';
                    foreach ($packs as $pack) {
                        $packId = 'pack_' . $pack['id'];
                        $packName = $pack['name'];
                        $apps = $pack['apps'];
                        $packDiv .= <<<FINE
<li data-jstree='{"opened": false}' id="$packId">
$packName
    <ul>
FINE;
                        foreach ($apps as $app) {
                            $appName = $app['name'];
                            $appId = 'app_' . $app['id'];
                            $img = '';
                            if ($app['adspace_image']) {
                                $imgs = explode(';', $app['adspace_image']);
                                $img = $siteUrl .'/'. array_pop($imgs);
                            }
                            $packDiv .= <<<FINE
<li data-jstree='{"selected": true}' data-thumbnail='$img' id="$appId">
$appName
</li>
FINE;
                        }
                        $packDiv .= "</ul></li>";
                    }
                    echo $packDiv . '</ul>';
                ?>
                  </div>
                  <div id="wap-pack-list-container" class='pack-list-container vam-hidden'>
                <?php
                    $packDiv = '<ul>';
                    foreach ($wapPacks as $pack) {
                        $packId = 'pack_' . $pack['id'];
                        $packName = $pack['name'];
                        $apps = $pack['apps'];
                        $packDiv .= <<<FINE
<li data-jstree='{"opened": false}' id="$packId">
$packName
    <ul>
FINE;
                        foreach ($apps as $app) {
                            $appName = $app['name'];
                            $appId = 'app_' . $app['id'];
                            $img = '';
                            if ($app['adspace_image']) {
                                $imgs = explode(';', $app['adspace_image']);
                                $img = $siteUrl .'/'. array_pop($imgs);
                            }
                            $packDiv .= <<<FINE
<li data-jstree='{"selected": true}' data-thumbnail='$img' id="$appId">
$appName
</li>
FINE;
                        }
                        $packDiv .= "</ul></li>";
                    }
                    echo $packDiv . '</ul>';
                ?>
                  </div>
                  <input type="hidden" id="pack_selected_list" name="pack_list" value="">
                  <div class="help-block text-error" id="rtb_target_pack_err"></div>
                </div>
                <div class="col-sm-5">
                  <div class="app-thumbnail-wrapper">
                    <img id="app-thumbnail-preview" class='vam-hidden' alt="APP 展示预览图">
                  </div>
                </div>
              </div>
            </div>
            <div id="pmp_resource_type" class="<?php if ($solution['is_pmp'] == 0) echo 'hidden';?>">
              <div class="hidden">
                <div class="form-group">
                  <label class="control-label col-sm-2">
                    <?=\Yii::t('solution', 'Target type')?>：
                  </label>
                  <div class="col-sm-10">
				    <?php
						if ($solution['is_pmp'] == 1) {
							$whiteChoice = \Yii::t('solution', 'white');
							echo $pmpBWDiv = <<<FINE
                    <label class="radio-inline">
                      <input id="adspace_black_white_radio" type="radio" name="adspace.black_white_radio" value="white" checked>
                    </label>
FINE;
						}
					?>
                  </div>
                </div>
                <div class="form-group">
                  <label for="rtb_network" class="col-sm-2 control-label">
                    <?=\Yii::t('solution', 'Market')?>：
                  </label>
                  <div class="col-sm-10">
				  <?php
						if ($solution['is_pmp'] == 1) {
							$whiteChoice = \Yii::t('solution', 'High Quality Resource');
							echo $pmpBWDiv = <<<FINE
								
					  <label class="radio-inline">
					  <input type="hidden" name="ad_network_id" value="1">
                      <input type="radio" name="ad_network[]" value="1" checked> $whiteChoice;
                    </label>
FINE;
						}
					?>
                  </div>
                </div>
              </div>
              <div class="form-group">
                <label for="" class="control-label col-sm-2">
                  PMP ID:
                </label>
                <div class="col-sm-5">
                  <input type="text" id="pmp_id" data-err="pmp_id_err" class="form-control" 
				  value="<?php 
					if ($solution['is_pmp'] == 1) 
						echo $solution['pmp_guid'];
				  ?>">
                  <div class="help-block text-error" id="pmp_id_err"></div>
                </div>
              </div>
              <div class="form-group">
                <label for="" class="control-label col-sm-2 pl0">
                  <?=\Yii::t('solution', 'PMP Adspaces')?>:
                </label>
                <div class="col-sm-10">
                  <select class="form-control" id="pmp_target_adspace" name="adspace.type[]" placeholder="<?=\Yii::t('solution', 'Please input keywords')?>" multiple>
				  <?php
						if ($solution['is_pmp'] == 1) {
							foreach ($pmpAdspaces as $pmpAd) {
								echo $adOption =<<<FINE
									<option value="{$pmpAd['id']}" selected>{$pmpAd['name']}</option>
FINE;
							}
						}
				  ?>
                  </select>
                </div>
              </div>
          </fieldset>
          <fieldset>
            <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10">
                <div class="btn-form-group pull-right">
                  <input class="operate-type" type="hidden" name="operate_type" value="save">
                  <button type="submit" class="btn btn-primary save-btn" data-operate="save" data-loading-text="<i class='fa fa-spinner fa-spin'></i> <?=\Yii::t('common', 'Saving')?>..."><?=\Yii::t('common', 'Save')?></button>
                  <button type="submit" class="btn btn-success save-next-btn" data-operate="save-next" data-loading-text="<i class='fa fa-spinner fa-spin'></i> <?=\Yii::t('common', 'Saving')?>...">
                    <?=\Yii::t('common', 'Save and Next')?>
                    <i class="fa fa-caret-right"></i>
                  </button>
                  <a href="<?php echo Url::to(['solution/solution-list']); ?>" class="btn btn-default">
                    <?=\Yii::t('common', 'Back')?>
                  </a>
                </div>
              </div>
            </div>
          </fieldset>
        </form>
      </div>
		</div>
	</div>
</div>
<?php
  $nextUrl = Url::to(['new-solution-target']);
  $pmpAdspaceList = Yii::getAlias('@web') . '/response/solution/pmpAdspaceList.php';
  $rtbAdspaceList = Url::to(['get-adnetwork-adspace']);
  $this->registerJs("VAM.setVar('NEXT_URL','$nextUrl');", View::POS_HEAD);
  $this->registerJs("VAM.setVar('PMP_ADSPACE_LIST','$pmpAdspaceList');", View::POS_END);
  $this->registerJs("VAM.setVar('RTB_ADSPACE_LIST','$rtbAdspaceList');", View::POS_END);
?>
<script type="text/javascript" >
  requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/site.js"], function(common) {
    requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/solution/newSolutionResource.js"]);
  });
</script>
